﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Infragistics.Win.UltraWinListView;

namespace ResponseMonitor
{
    public partial class DeleteForm : Form
    {
        public DeleteForm()
        {
            InitializeComponent();
        }

        private void DeleteForm_Load(object sender, EventArgs e)
        {
            string [] dirs = Directory.GetDirectories(Settings.Default.SavePath);
            foreach (string d in dirs)
            {
                string dName = d.Substring(d.LastIndexOf("\\") + 1);
                string sName = dName.Substring(dName.IndexOf("_") + 1);
                ultraListViewDirs.Items.Add(new UltraListViewItem(sName, null, null));
            }
        }

        private void ultraButtonDelete_Click(object sender, EventArgs e)
        {
            if (ultraListViewDirs.SelectedItems.Count <= 0)
            {
                MessageBox.Show("Please select a project to delete!");
                return;
            }

            UltraListViewItem sItem = ultraListViewDirs.SelectedItems.First;
            string name = sItem.Text;
            string fName = Settings.Default.SavedDataPrefix + "_" + name;
            string fullName = Settings.Default.SavePath + "\\" + fName;

            if (MessageBox.Show(string.Format("Are you sure you want to delete the project: {0}?", fullName), "Delete project...", MessageBoxButtons.YesNo) == DialogResult.No)
                return;

            Directory.Delete(fullName, true);
            ultraListViewDirs.Items.Remove(sItem);
        }

        private void ultraButtonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
